<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */
include_once("../../config.inc.php");
include(__Modules_Path."/ChangeTime.lib.php");
include_once("WebConfig.php");

$strTmp = "{ 'Web' : '{ShowWeb}', 'WebID' : '{ShowWebID}', 'GID' : '{ShowGID}', 'SNo' : '{ShowSerailNo}', 'OSNo' : '{ShowOSerailNo}', 'DTime' : '{ShowDateTime}', 'ETime' : '{ShowEndTime}', 'Status' : '{ShowStatus}', 'BTOff' : '{ShowBTOff}' }";

$arrGame = array();
$arrOpenOff = array();
foreach($arrWeb as $k => $arrW){
	$strName = $arrW[0];
	$strDir = $arrW[1];

	$arrGID = array(5 => 0, 6 => 0, 7 => 0, 8 => 0);
	include("/home/share/www/".$strDir."/secure/db.inc.php");

	$strSQL = "(select * from `bet_Gamble` where LottoID = 5 order by ID desc limit 1)
				union (select * from `bet_Gamble` where LottoID = 6 order by ID desc limit 1)
				union (select * from `bet_Gamble` where LottoID = 7 order by ID desc limit 1)
				union (select * from `bet_Gamble` where LottoID = 8 order by ID desc limit 1)
	";
	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	if(PMA_mysql_num_rows($RS) == 0)continue;

	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrGame[$Rows -> LottoID][$k] = $Rows;
		$arrGID[$Rows -> LottoID] = $Rows -> ID;
		$arrOpenOff[$Rows -> LottoID][$k] = "0 / 0";
	}

	$strSQL = "(select LottoID, SUM(IF(isStopBet = 1, 1, 0)) as OffNo, SUM(IF(isStopBet = 0, 1, 0)) as OpenNo from `bet_TodayGame5` where LottoID = 5 and GambleID = '".$arrGID[5]."' group by LottoID)
				union (select LottoID, SUM(IF(isStopBet = 1, 1, 0)) as OffNo, SUM(IF(isStopBet = 0, 1, 0)) as OpenNo from `bet_TodayGame6` where LottoID = 6 and GambleID = '".$arrGID[6]."' group by LottoID)
				union (select LottoID, SUM(IF(isStopBet = 1, 1, 0)) as OffNo, SUM(IF(isStopBet = 0, 1, 0)) as OpenNo from `bet_TodayGame7` where LottoID = 7 and GambleID = '".$arrGID[7]."' group by LottoID)
				union (select LottoID, SUM(IF(isStopBet = 1, 1, 0)) as OffNo, SUM(IF(isStopBet = 0, 1, 0)) as OpenNo from `bet_TodayGame8` where LottoID = 8 and GambleID = '".$arrGID[8]."' group by LottoID)
	";

	$RS = @PMA_mysql_query($strSQL, $$_Conn);
	if(PMA_mysql_num_rows($RS) == 0)continue;

	while($Rows = PMA_mysql_fetch_object($RS)){
		$arrOpenOff[$Rows -> LottoID][$k] = $Rows -> OpenNo." / ".$Rows -> OffNo;
	}

	@mysql_free_result($RS);
	@mysql_close($$_Conn);
}

$arrLottoID = array(5, 6, 7, 8);
$strCon = "";
$arrCon = array();
foreach($arrLottoID as $intLID){
	$arrTmp  = array();
	foreach($arrWeb as $k => $arrW){
		$strName = $arrW[0];
		$strDir = $arrW[1];

		$strTmp1 = $strTmp;
		$strTmp1 = str_replace("{ShowWeb}", $strName." ( ".$strDir." )", $strTmp1);
		$strTmp1 = str_replace("{ShowWebID}", $k, $strTmp1);

		if($arrGame[$intLID][$k] == null){
			$strTmp1 = str_replace("{ShowGID}", "0", $strTmp1);
			$strTmp1 = str_replace("{ShowSerailNo}", "0", $strTmp1);
			$strTmp1 = str_replace("{ShowOSerailNo}", "0", $strTmp1);
			$strTmp1 = str_replace("{ShowStatus}", "無", $strTmp1);
			$strTmp1 = str_replace("{ShowDateTime}", "0000-00-00 00:00:00", $strTmp1);
			$strTmp1 = str_replace("{ShowEndTime}", "00:00:00", $strTmp1);
			$strTmp1 = str_replace("{ShowBTOff}", "0 / 0", $strTmp1);

		}else{
			$objGame = $arrGame[$intLID][$k];
			$strOpenOff = $arrOpenOff[$intLID][$k];

			$strTmp1 = str_replace("{ShowGID}", $objGame -> ID, $strTmp1);
			$strTmp1 = str_replace("{ShowSerailNo}", $objGame -> SerialNo, $strTmp1);
			$strTmp1 = str_replace("{ShowOSerailNo}", $objGame -> OSerialNo, $strTmp1);
			$strTmp1 = str_replace("{ShowStatus}", ($objGame -> isEnd == 1?"已結束":"進行中"), $strTmp1);

			$strGDate = DateForm($objGame -> GameDate, $objGame -> GameTime, "Y-m-d");
			$strGTime = TimeForm($objGame -> GameDate, $objGame -> GameTime, "H:i:s");
			$strEndGTime = TimeForm($objGame -> GameDate, $objGame -> EndGameTime, "H:i:s");

			$strTmp1 = str_replace("{ShowDateTime}", $strGDate." ".$strGTime, $strTmp1);
			$strTmp1 = str_replace("{ShowEndTime}", $strEndGTime, $strTmp1);
			$strTmp1 = str_replace("{ShowBTOff}", $strOpenOff, $strTmp1);
		}
		$arrTmp[] = $strTmp1;
	}
	$arrCon[] = "[ ".implode(",", $arrTmp)."]";
}
$strCon = "[ ".implode(",", $arrCon)."]";
WebOutputHTML($strCon, 1);
?>